package com.suray.wcs.service.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.suray.wcs.service.system.entity.InterfaceLogDB;
import com.suray.wcs.service.system.entity.InterfaceLogRvg;
import com.suray.wcs.service.system.mapper.InterfaceLogRgvMapper;
import com.suray.wcs.service.system.service.InterfaceLogRgvService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class InterfaceLogRgvServiceImpl extends ServiceImpl<InterfaceLogRgvMapper, InterfaceLogRvg> implements InterfaceLogRgvService {

    @Autowired
    InterfaceLogRgvMapper interfaceLogRgvMapper;

    @Override
    public List<InterfaceLogRvg> getInterfaceLogsRgv(InterfaceLogRvg interfaceLogRvg) {
        LambdaQueryWrapper<InterfaceLogRvg> queryWrapper = new LambdaQueryWrapper();
        if (!StringUtils.isEmpty(interfaceLogRvg.getTackId())) {
            queryWrapper.like(InterfaceLogRvg::getTackId, interfaceLogRvg.getTackId());
        }
        if (!StringUtils.isEmpty(interfaceLogRvg.getDeviceName())) {
            queryWrapper.like(InterfaceLogRvg::getDeviceName, interfaceLogRvg.getDeviceName());
        }
        if (!StringUtils.isEmpty(interfaceLogRvg.getMessage())) {
            queryWrapper.like(InterfaceLogRvg::getMessage, interfaceLogRvg.getMessage());
        }
        if (interfaceLogRvg.getSendTimeStart() != null) {
            queryWrapper.gt(InterfaceLogRvg::getOperateTime, interfaceLogRvg.getSendTimeStart());
        }
        if (interfaceLogRvg.getSendTimeEnd() != null) {
            queryWrapper.lt(InterfaceLogRvg::getOperateTime, interfaceLogRvg.getSendTimeEnd());
        }
        queryWrapper.orderByDesc(InterfaceLogRvg::getOperateTime);

        return interfaceLogRgvMapper.selectList(queryWrapper);
    }

    @Override
    public boolean setInterfaceLogRgv(InterfaceLogRvg interfaceLogRvg) {
        return this.save(interfaceLogRvg);
    }

    @Override
    public void deleteThreeDaysIfLogRgv(Integer days) {
        interfaceLogRgvMapper.deleteThreeDaysIfLog(days);
    }



}
